﻿namespace Smart.ERP
{
    using Smart.Data.Helper;
    using Smart.Utils.Lib;
    using System;
    using System.Data;
    using System.Data.SqlClient;
    using System.Windows.Forms;

    public class SYS_OPTION
    {
        private static bool m_Batch = false;
        private static string m_Currency = "VND";
        private string m_Description;
        private static string m_Language = "VN";
        private static bool m_Limit = false;
        private static bool m_Negative = false;
        private string m_Option_ID;
        private string m_OptionValue;
        private static string m_ReportLanguage = "VN";
        private static string m_ReportLocalization = "vi-VN";
        private int m_ValueType;

        public SYS_OPTION()
        {
            this.m_Option_ID = "";
            this.m_OptionValue = "";
            this.m_ValueType = 0;
            this.m_Description = "";
        }

        public SYS_OPTION(string Option_ID, string OptionValue, int ValueType, string Description)
        {
            this.m_Option_ID = Option_ID;
            this.m_OptionValue = OptionValue;
            this.m_ValueType = ValueType;
            this.m_Description = Description;
        }

        public void AddCombo(ComboBox combo)
        {
            MyLib.TableToComboBox(combo, this.GetList(), "SYS_OPTIONName", "SYS_OPTIONID");
        }

        public void AddComboAll(ComboBox combo)
        {
            DataTable list = new DataTable();
            list = this.GetList();
            DataRow row = list.NewRow();
            row["SYS_OPTIONID"] = "All";
            row["SYS_OPTIONName"] = "Tất cả";
            list.Rows.InsertAt(row, 0);
            MyLib.TableToComboBox(combo, list, "SYS_OPTIONName", "SYS_OPTIONID");
        }

        public string Delete()
        {
            string[] myParams = new string[] { "@Option_ID" };
            object[] myValues = new object[] { this.m_Option_ID };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("SYS_OPTION_Delete", myParams, myValues);
        }

        public string Delete(string Option_ID)
        {
            string[] myParams = new string[] { "@Option_ID" };
            object[] myValues = new object[] { Option_ID };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("SYS_OPTION_Delete", myParams, myValues);
        }

        public string Delete(SqlConnection myConnection, string Option_ID)
        {
            string[] myParams = new string[] { "@Option_ID" };
            object[] myValues = new object[] { Option_ID };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myConnection, "SYS_OPTION_Delete", myParams, myValues);
        }

        public string Delete(SqlTransaction myTransaction, string Option_ID)
        {
            string[] myParams = new string[] { "@Option_ID" };
            object[] myValues = new object[] { Option_ID };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "SYS_OPTION_Delete", myParams, myValues);
        }

        public bool Exist(string Option_ID)
        {
            bool hasRows = false;
            string[] myParams = new string[] { "@Option_ID" };
            object[] myValues = new object[] { Option_ID };
            SqlHelper helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader("SYS_OPTION_Get", myParams, myValues);
            if (reader != null)
            {
                hasRows = reader.HasRows;
                reader.Close();
                helper.Close();
                reader = null;
            }
            return hasRows;
        }

        public string Get(string Option_ID)
        {
            string str = "";
            string[] myParams = new string[] { "@Option_ID" };
            object[] myValues = new object[] { Option_ID };
            SqlHelper helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader("SYS_OPTION_Get", myParams, myValues);
            if (reader != null)
            {
                while (reader.Read())
                {
                    this.m_Option_ID = Convert.ToString(reader["Option_ID"]);
                    this.m_OptionValue = Convert.ToString(reader["OptionValue"]);
                    this.m_ValueType = Convert.ToInt32(reader["ValueType"]);
                    this.m_Description = Convert.ToString(reader["Description"]);
                    str = "OK";
                }
                reader.Close();
                helper.Close();
                reader = null;
            }
            return str;
        }

        public string Get(SqlConnection myConnection, string Option_ID)
        {
            string str = "";
            string[] myParams = new string[] { "@Option_ID" };
            object[] myValues = new object[] { Option_ID };
            SqlHelper helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader(myConnection, "SYS_OPTION_Get", myParams, myValues);
            if (reader != null)
            {
                while (reader.Read())
                {
                    this.m_Option_ID = Convert.ToString(reader["Option_ID"]);
                    this.m_OptionValue = Convert.ToString(reader["OptionValue"]);
                    this.m_ValueType = Convert.ToInt32(reader["ValueType"]);
                    this.m_Description = Convert.ToString(reader["Description"]);
                    str = "OK";
                }
                reader.Close();
                helper.Close();
                reader = null;
            }
            return str;
        }

        public string Get(SqlTransaction myTransaction, string Option_ID)
        {
            string str = "";
            string[] myParams = new string[] { "@Option_ID" };
            object[] myValues = new object[] { Option_ID };
            SqlHelper helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader(myTransaction, "SYS_OPTION_Get", myParams, myValues);
            if (reader != null)
            {
                while (reader.Read())
                {
                    this.m_Option_ID = Convert.ToString(reader["Option_ID"]);
                    this.m_OptionValue = Convert.ToString(reader["OptionValue"]);
                    this.m_ValueType = Convert.ToInt32(reader["ValueType"]);
                    this.m_Description = Convert.ToString(reader["Description"]);
                    str = "OK";
                }
                reader.Close();
                helper.Close();
                reader = null;
            }
            return str;
        }

        public DataTable GetList()
        {
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteDataTable("SYS_OPTION_GetList");
        }

        public string Insert()
        {
            string[] myParams = new string[] { "@Option_ID", "@OptionValue", "@ValueType", "@Description" };
            object[] myValues = new object[] { this.m_Option_ID, this.m_OptionValue, this.m_ValueType, this.m_Description };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("SYS_OPTION_Insert", myParams, myValues);
        }

        public string Insert(SqlTransaction myTransaction)
        {
            string[] myParams = new string[] { "@Option_ID", "@OptionValue", "@ValueType", "@Description" };
            object[] myValues = new object[] { this.m_Option_ID, this.m_OptionValue, this.m_ValueType, this.m_Description };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "SYS_OPTION_Insert", myParams, myValues);
        }

        public string Insert(string Option_ID, string OptionValue, int ValueType, string Description)
        {
            string[] myParams = new string[] { "@Option_ID", "@OptionValue", "@ValueType", "@Description" };
            object[] myValues = new object[] { Option_ID, OptionValue, ValueType, Description };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("SYS_OPTION_Insert", myParams, myValues);
        }

        public string Insert(SqlConnection myConnection, string Option_ID, string OptionValue, int ValueType, string Description)
        {
            string[] myParams = new string[] { "@Option_ID", "@OptionValue", "@ValueType", "@Description" };
            object[] myValues = new object[] { Option_ID, OptionValue, ValueType, Description };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myConnection, "SYS_OPTION_Insert", myParams, myValues);
        }

        public string Insert(SqlTransaction myTransaction, string Option_ID, string OptionValue, int ValueType, string Description)
        {
            string[] myParams = new string[] { "@Option_ID", "@OptionValue", "@ValueType", "@Description" };
            object[] myValues = new object[] { Option_ID, OptionValue, ValueType, Description };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "SYS_OPTION_Insert", myParams, myValues);
        }

        public static void Load()
        {
            SYS_OPTION sys_option = new SYS_OPTION();
            sys_option.Get("Language_Id");
            m_Language = (sys_option.OptionValue == "") ? "VN" : sys_option.OptionValue;
        }

        public static void LoadBatch()
        {
            SYS_OPTION sys_option = new SYS_OPTION();
            sys_option.Get("Batch");
            m_Batch = sys_option.OptionValue == "1";
        }

        public static void LoadCurrency()
        {
            SYS_OPTION sys_option = new SYS_OPTION();
            sys_option.Get("Currency");
            try
            {
                m_Currency = Convert.ToString(sys_option.OptionValue);
            }
            catch (Exception)
            {
                m_Currency = "VND";
            }
        }

        public static void LoadLimit()
        {
            SYS_OPTION sys_option = new SYS_OPTION();
            sys_option.Get("Limit");
            m_Limit = sys_option.OptionValue == "1";
        }

        public static void LoadNegative()
        {
            SYS_OPTION sys_option = new SYS_OPTION();
            sys_option.Get("Negative");
            m_Negative = sys_option.OptionValue == "1";
        }

        public string NewID()
        {
            return SqlHelper.GenCode("SYS_OPTION", "SYS_OPTIONID", "");
        }

        public string Update()
        {
            string[] myParams = new string[] { "@Option_ID", "@OptionValue", "@ValueType", "@Description" };
            object[] myValues = new object[] { this.m_Option_ID, this.m_OptionValue, this.m_ValueType, this.m_Description };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("SYS_OPTION_Update", myParams, myValues);
        }

        public string Update(string Option_ID, string OptionValue, int ValueType, string Description)
        {
            string[] myParams = new string[] { "@Option_ID", "@OptionValue", "@ValueType", "@Description" };
            object[] myValues = new object[] { Option_ID, OptionValue, ValueType, Description };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("SYS_OPTION_Update", myParams, myValues);
        }

        public string Update(SqlConnection myConnection, string Option_ID, string OptionValue, int ValueType, string Description)
        {
            string[] myParams = new string[] { "@Option_ID", "@OptionValue", "@ValueType", "@Description" };
            object[] myValues = new object[] { Option_ID, OptionValue, ValueType, Description };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myConnection, "SYS_OPTION_Update", myParams, myValues);
        }

        public string Update(SqlTransaction myTransaction, string Option_ID, string OptionValue, int ValueType, string Description)
        {
            string[] myParams = new string[] { "@Option_ID", "@OptionValue", "@ValueType", "@Description" };
            object[] myValues = new object[] { Option_ID, OptionValue, ValueType, Description };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "SYS_OPTION_Update", myParams, myValues);
        }

        public static bool Batch
        {
            get
            {
                return m_Batch;
            }
            set
            {
                m_Batch = value;
            }
        }

        public static string Currency
        {
            get
            {
                return m_Currency;
            }
            set
            {
                m_Currency = value;
            }
        }

        public string Description
        {
            get
            {
                return this.m_Description;
            }
            set
            {
                this.m_Description = value;
            }
        }

        public static string Language
        {
            get
            {
                return m_Language;
            }
            set
            {
                m_Language = value;
            }
        }

        public static bool Limit
        {
            get
            {
                return m_Limit;
            }
            set
            {
                m_Limit = value;
            }
        }

        public static bool Negative
        {
            get
            {
                return m_Negative;
            }
            set
            {
                m_Negative = value;
            }
        }

        public string Option_ID
        {
            get
            {
                return this.m_Option_ID;
            }
            set
            {
                this.m_Option_ID = value;
            }
        }

        public string OptionValue
        {
            get
            {
                return this.m_OptionValue;
            }
            set
            {
                this.m_OptionValue = value;
            }
        }

        public string ProductName
        {
            get
            {
                return "Class SYS_OPTION";
            }
        }

        public string ProductVersion
        {
            get
            {
                return "1.0.0.0";
            }
        }

        public static string ReportLanguage
        {
            get
            {
                return m_ReportLanguage;
            }
            set
            {
                m_ReportLanguage = value;
            }
        }

        public static string ReportLocalization
        {
            get
            {
                return m_ReportLocalization;
            }
            set
            {
                m_ReportLocalization = value;
            }
        }

        public int ValueType
        {
            get
            {
                return this.m_ValueType;
            }
            set
            {
                this.m_ValueType = value;
            }
        }
    }
}

